const toString = Object.prototype.toString;

export function is(val: unknown, type: string) {
  return toString.call(val) === `[object ${type}]`;
}

export function isDef(val: any): boolean {
  return typeof val !== 'undefined';
}

export function isUnDef(val: any): boolean {
  return !isDef(val);
}

export function isObject(val: any): boolean {
  return val !== null && is(val, 'Object');
}

export function isDate(val: any): boolean {
  return is(val, 'Date');
}

export function isNumber(val: any): boolean {
  return is(val, 'Number');
}

export function isString(val: any): boolean {
  return is(val, 'String');
}

export function isFunction(val: unknown): boolean {
  return typeof val === 'function';
}

export function isBoolean(val: unknown): boolean {
  return is(val, 'boolean');
}

export function isRegExp(val: unknown): boolean {
  return is(val, 'RegExp');
}

export function isArray(val: any): boolean {
  return val && is(val, 'Array');
}
